package com.woniu.tms.manage.controller;

import com.woniu.tms.manage.service.UserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("manage/userrole")
public class UserRoleController {

    @Autowired
    UserRoleService userRoleService;

    /**
     * 给用户分配角色
     * @param uid
     * @param rids
     * @return
     */
    @RequestMapping("assignRoleDo")
    @ResponseBody
    public Map<String, Object> assignRoleDo(Integer uid, Integer[] rids) {
        Map<String, Object> map = new HashMap<>();
        try {
            userRoleService.add(uid, rids);
            map.put("result", true);
        } catch (Exception e) {
            map.put("result", false);
        }
        return map;
    }

    /**
     * 给用户删除角色
     * @param uid
     * @param rids2
     * @return
     */
    @RequestMapping("unAssignRoleDo")
    @ResponseBody
    public Map<String, Object> unAssignRoleDo(Integer uid, Integer[] rids2) {
        Map<String, Object> map = new HashMap<>();
        try {
            userRoleService.delete(uid, rids2);
            map.put("result", true);
        } catch (Exception e) {
            map.put("result", false);
        }
        return map;
    }


}
